package yiyuan.code.filedemo.file.config;
//import com.sccin.tenant.datasource.api.ITenantDataSourceService;
//import com.sccin.tenant.datasource.api.pojo.DynamicDataSource;
//import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

/**
 * 数据源支持
 */

@Configuration
public class DataSourseConfig {

    ////数据隔离服务
    //@DubboReference
    //private ITenantDataSourceService tenantDataSourceService;
    //
    ////业务库公共数据源
    //@Bean(name = "businessDataSource")
    //@Qualifier("businessDataSource")
    //@ConfigurationProperties("spring.datasource.hikari.microbusinessdefault")
    //public DataSource businessDataSource() {
    //    return DataSourceBuilder.create().build();
    //}
    //
    ///**
    // * 动态数据源
    // *
    // * @param businessDataSource 业务库公共数据源
    // */
    //@Primary
    //@Bean(name = "primaryDataSource")
    //@Qualifier("primaryDataSource")
    //public DataSource primaryDataSource(DataSource businessDataSource) {
    //
    //    return new DynamicDataSource(businessDataSource, tenantDataSourceService);
    //}

    @Primary
    @Bean(name = "primaryDataSource")
    @Qualifier("primaryDataSource")
    @ConfigurationProperties("spring.datasource.hikari.primary")
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create().build();
    }
}
